import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author lzm
 * @date 2025/2/28 20:04
 * @description 单例线程池
 */
public class ThreadPoolManager {

    private static AtomicInteger counter = new AtomicInteger(1);

    private static final ThreadPoolExecutor THREAD_POOL = new CustomThreadPool(2, 2,
            1, TimeUnit.HOURS, new LinkedBlockingQueue<>(1),
            r -> new Thread(r, "线程-" + counter.getAndIncrement()),
            new ThreadPoolExecutor.AbortPolicy());

    private ThreadPoolManager() {
    }

    /**
     * 获取单例的线程池
     *
     * @return 线程池
     */
    public static ThreadPoolExecutor get() {
        return THREAD_POOL;
    }

}
